#!/usr/bin/env python
# -*- coding: utf-8 -*-

from bs4 import BeautifulSoup


# page = '<head>\n<meta charset="utf-8" />\n</head>\n<body>\n<a href="http://www.baidu.com/" target="_blank">跳转到baidu</a>\n</body>'
# https://www.crummy.com/software/BeautifulSoup/bs4/doc.zh/
page = """<html>
<head>
<title>The Dormouse's story</title>
</head>

<body>
<p class="title"><b>The Dormouse's story</b></p>
<p class="story">Once upon a time there were three little sisters; and their names were
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>,
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
and they lived at the bottom of a well.</p>
<p class="story">...</p>
</body>
</html>
"""
print(page)
print('-' * 10)
soup = BeautifulSoup(page, features='lxml')
print(soup)
print('-' * 10)
body = soup.select('body')[0]
print(body)
print(type(body))
print('-' * 10)
print(body.select('a')[0]['href'])
print(body.select('a')[0].text)
print(body.a)

# soup.select('div')
# # All elements named <div>
#
# soup.select('#author')
# # The element with an id attribute of author
#
# soup.select('.notice')
# # All elements that use a CSS class attribute named notice
#
# soup.select('div span')
# # All elements named <span> that are within an element named <div>
#
# soup.select('div > span')
# # All elements named <span> that are directly within an element named <div>,
# # with no other element in between
#
# soup.select('input[name]')
# # All elements named <input> that have a name attribute with any value
#
# soup.select('input[type="button"]')
# # All elements named <input> that have an attribute named type with value button
